<template>
  <div>
    <el-input placeholder="输入关键字进行过滤" v-model="filterText"></el-input>
    <div class="tree">
      <el-tree
      :data="menus"
      :props="defaultProps"
      node-key="id"
      ref="menuTree"
      @node-click="nodeclick"
      :filter-node-method="filterNode"
      :highlight-current="true"
    ></el-tree>
    </div>
  </div>
</template>

<script>
import PubSub from "pubsub-js";
export default {
  //import引入的组件需要注入到对象中才能使用
  components:{},
  props:{},
  data(){
    return {
      filterText: "",
      menus: [],
      expandedKey: [],
      defaultProps: {
        label: "description",
        children:[]
      },
    };
  },
  computed:{},
  watch:{
    filterText(val) {
      this.$refs.menuTree.filter(val)
    },
  },
  methods:{
    filterNode(value,data){
      if (!value) return true;
      return data.description.indexOf(value) !== -1
    },
    getMenus(){
      this.$http({
        url: this.$http.adornUrl("/dict/tbbasedict/listAll"),
        method: "get"
      }).then(({ data }) => {
        this.menus = data.list
      });
    },
    nodeclick(data,node,component){
      // 向父组件发送事件
      this.$emit("tree-node-click", data, node, component)
    },
  },
  created(){
    this.getMenus()
  },
  mounted(){},
  beforeCreate(){},
  beforeMount(){},
  beforeUpdate(){},
  updated(){},
  beforeDestroy(){},
  destroyed(){},
  activated(){}
};
</script>
<style scoped>
  .tree{
    height: 467px;
    overflow: auto;
  }
</style>
